$(document).ready(function() {

    function createSuccessMsg (loc, msg) {
        console.log(msg);
        loc.append(
            '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">&times;</button><strong><i class="en-checkmark s24"></i> 注册成功！</strong> '+ msg + ' </div>'
        );
    }

    $("#wizard").formwizard({
        formPluginEnabled: true,
        validationEnabled: false,
        focusFirstInput : true,
        formOptions :{
            success: function(data){
                //produce success message
                console.log(data);
                createSuccessMsg($("#wizard .msg"), "学生学号："+$("#stuNum").val()+"----学生密码："+$("#stuPassword").val());
            },
            resetForm: true
        },
        disableUIStyles: true,
        showSteps: true //show the step
    });
});
$(document).on('click', '#next-btn', function() {
    console.log($("#stuNum").val());
    console.log($("#stuPassword").val());

    var $stuNum=$("#stuNum").val();
    var $stuPassword=$("#stuPassword").val();

    $.ajax({
        url: "http://localhost:8080/student/queryStuNum?stuNum="+$stuNum,
        type: "GET",
        async: false,
        dataType: "json",
        contentType:"application/json",
        success:function (data) {
            console.log("data.code="+data.code);
            if (data.code==0){
                var studata = {
                    stuNum:$stuNum,
                    stuPassword:$stuPassword,
                };
                $.ajax({
                    url: "http://localhost:8080/student/addStudent",
                    type: "POST",
                    async: false,
                    data:JSON.stringify(studata),
                    dataType: "json",
                    contentType:"application/json",
                    success:function () {
                        layer.msg('注册成功', function(){
                            window.location.href="studentRegister.html";
                        });
                    },
                    error:function () {
                        layer.msg("网络在开小差~稍后重试");
                    }
                });

            }else {
                layer.msg("该学号已存在！");
            }

        },
        error:function () {
            layer.msg("网络在开小差~稍后重试");
        }
    });
});
